/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(
  initialState: { currentUser?: API.CurrentUser; roleInfo?: any } | undefined,
) {
  const { currentUser, roleInfos, permissions } = initialState ?? {};
  // debugger;
  return {
    // canAdmin: currentUser && currentUser.access === 'admin',
    canAdmin: () => {
      return currentUser?.roleInfos.includes('ROLE_001');
    },
    normalRouteFilter: (route) => {
      // console.log(route, '---route----');
      return currentUser?.permissionInfos.includes(route.name);
    },

    aperatorFilter: (name) => {
      // console.log(route, '---route----');
      return currentUser?.permissionInfos.includes(name);
    },
    canEngineer: () => {
      return currentUser?.roleInfos.includes('ROLE_002');
    },

    // 主任工程师
    canChiefEngineer: () => {
      return currentUser?.roleInfos.includes('ROLE_004');
    },

    canCustomer: () => {
      return currentUser?.roleInfos.includes('ROL_003');
    },

    canCustomerAdmin: () => {
      return currentUser?.roleInfos.includes('ROLE_005');
    },
  };
}
